﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class AmountHistory : IAccessible<P_AmountHistory, AmountHistory>, ILogicEntity<P_AmountHistory, AmountHistory>
    {
        public int ID { get; set; }
        public string UserName { get; set; }
        public string TransactionUser { get; set; }
        public AmountOperationType OperationType { get; set; }
        public decimal ChangeValue { get; set; }
        public decimal PreAmount { get; set; }
        public decimal CurrentAmount { get; set; }
        public decimal PreFreeze { get; set; }
        public decimal CurrentFreeze { get; set; }
        public DateTime CreateTime { get; set; }
        public string Remark { get; set; }
        public int AmountOperationID { get; set; }

        protected override void Covariant(P_AmountHistory model)
        {
            if (model != null)
            {
                this.ID = model.ID;
                this.UserName = model.UserName;
                this.TransactionUser = model.TransactionUser;
                this.OperationType = (AmountOperationType)model.OperationType;
                this.ChangeValue = model.ChangeValue;
                this.PreAmount = model.PreAmount;
                this.CurrentAmount = model.CurrentAmount;
                this.PreFreeze = model.PreAmount;
                this.CurrentFreeze = model.CurrentFreeze;
                this.CreateTime = model.CreateTime;
                this.Remark = model.Remark;
                this.AmountOperationID = model.AmountOperationID;
            }
        }

        protected override P_AmountHistory Inverter(AmountHistory model)
        {
            if (model != null)
            {
                return new P_AmountHistory()
                {
                    AmountOperationID = model.AmountOperationID,
                    ChangeValue = model.ChangeValue,
                    CreateTime = model.CreateTime,
                    CurrentAmount = model.CurrentAmount,
                    CurrentFreeze = model.CurrentFreeze,
                    ID = model.ID,
                    OperationType = (int)model.OperationType,
                    PreAmount = model.PreAmount,
                    PreFreeze = model.PreFreeze,
                    Remark = model.Remark,
                    TransactionUser = model.TransactionUser,
                    UserName = model.UserName
                };
            }
            return null;
        }

        public AmountHistory Set(P_AmountHistory dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
